import Vue from 'vue'
import VueRouter from 'vue-router'
import wxChat from "../utils/wxShare";

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
const routes = [
    {
        path: '',
        component: () => import('../views/Home'),
        children: [{path: '', component: () => import('../views/Home_index'), meta: {title: "黑侠的小圈子"}}]
    },
    {
        path: '/',
        component: () => import('../views/Home'),
        children: [{path: '', component: () => import('../views/Home_index'), meta: {title: "黑侠的小圈子"}}]
    },
    {path: '/login', component: () => import('../views/users/Login'), meta: {title: "登录-黑侠的小圈子"}},
    {path: '/register', component: () => import('../views/users/Register'), meta: {title: "注册-黑侠的小圈子"}},
    {path: '/userbind', component: () => import('../views/users/UserBind'), meta: {title: "绑定-黑侠的小圈子"}},
    {path: '/changegassword', component: () => import('../views/users/ChangePassword'), meta: {title: "修改密码-黑侠的小圈子"}},
    {path: '/emailcode', component: () => import("../views/users/EmailCode"), meta: {title: "验证邮箱-黑侠的小圈子"}},
    {path: '/bindemail',component: () => import("../views/users/BindEmail"), meta: {title: "绑定邮箱-黑侠的小圈子"}},
    {path: '/forget', component: () => import("../views/users/Forget"), meta: {title: "忘记密码-黑侠的小圈子"}},
    {
        path: '/server',
        component: () => import('../views/server/Server'),
        children: [
            {path: '', component: () => import('../views/server/ServerInfo'), meta: {title: "服务器管理-黑侠的小圈子"}},
            {path: 'serverinfo', component: () => import('../views/server/ServerInfo'), meta: {title: "服务器管理-黑侠的小圈子"}},
            {
                path: 'serveredit/:id/:ip/:yhm/:mm/:dqsj/:fws/:dy/:yyz/:bz',
                component: () => import('../views/server/ServerEdit'),
                name: 'edit',
                meta: {title: "修改服务器信息-黑侠的小圈子"}
            },
            {path: 'serveradd', component: () => import('../views/server/ServerAdd'), meta: {title: "添加服务器-黑侠的小圈子"}},
            {path: 'recycle', component: () => import('../views/server/ServerRecycle'), meta: {title: "服务器回收站-黑侠的小圈子"}},
            {path: 'lease', component: () => import('../views/server/ServerLease'), meta: {title: "服务器租赁-黑侠的小圈子"}},
            {
                path: 'leaseadd',
                component: () => import('../views/server/ServerLeaseAdd'),
                meta: {title: "添加服务器租赁-黑侠的小圈子"}
            },
            {
                path: 'leaseedit/:valuse',
                component: () => import('../views/server/ServerLeaseEdit'),
                name: "lease_edit",
                meta: {title: "修改服务器租赁-黑侠的小圈子"}
            },
            {
                path: 'leasefinish',
                component: () => import('../views/server/ServerLeaseFinish'),
                meta: {title: "历史服务器租赁-黑侠的小圈子"}
            },

        ]
    },
    {
        path: '/home', component: () => import('../views/Home'), children: [
            {path: '', component: () => import('../views/Home_index'), meta: {title: "黑侠的小圈子"}},
            {path: 'index', component: () => import('../views/Home_index'), meta: {title: "黑侠的小圈子"}},
        ]
    },
    {
        path: '/goInformantGroup',
        component: () => import('../views/order/GoInformantGroup'),
        meta: {title: "进入线报群-黑侠的小圈子"}
    },
    {
        path: '/user', component: () => import('../views/users/User'), children: [
            {path: '', component: () => import('../views/order/UserOrder'), meta: {title: "我的订单-黑侠的小圈子"}},
            {path: 'userinfo', component: () => import('../views/users/UserInfo'), meta: {title: "用户列表-黑侠的小圈子"}},
            {
                path: 'userbalance',
                component: () => import('../views/users/UserBalance'),
                meta: {title: "修改用户余额-黑侠的小圈子"}
            },
            {
                path: 'useredit/:valuse',
                name: 'useredit',
                component: () => import('../views/users/UserEdit'),
                meta: {title: "修改用户信息-黑侠的小圈子"}
            },
            {path: 'userorder', component: () => import('../views/order/UserOrder'), meta: {title: "我的订单-黑侠的小圈子"}},
            {path: 'personal', component: () => import('../views/users/Personal'), meta: {title: "我的信息-黑侠的小圈子"}},
            {path: 'pay', component: () => import('../views/users/WxPay'), meta: {title: "余额充值-黑侠的小圈子"}},
            {
                path: 'userorderall',
                component: () => import('../views/order/UserOrderAll'),
                meta: {title: "订单列表-黑侠的小圈子"}
            },
            {
                path: 'userbill',
                name: 'userbill',
                component: () => import('../views/users/UserBill'),
                meta: {title: "余额变动-黑侠的小圈子"}
            },
            {
                path: 'log',
                name: 'log',
                component: () => import('../views/users/UserLog'),
                meta: {title: "登录日志-黑侠的小圈子"}
            },
        ]
    },
    {
        path: "/perception", component: () => import('../views/article/Perception'), children: [
            {path: '', component: () => import('../views/article/PerceptionALL'), meta: {title: "最新文章-黑侠的小圈子"}},
            {path: 'add', component: () => import('../views/article/PerceptionAdd'), meta: {title: "发布文章-黑侠的小圈子"}},
            {path: 'look', component: () => import('../views/article/PerceptionLook'), name: 'perceptionlook'},
            {path: 'all', component: () => import('../views/article/PerceptionALL'), meta: {title: "最新文章-黑侠的小圈子"}},
            {
                path: 'lookall',
                component: () => import('../views/article/PerceptionUserAll'),
                meta: {title: "我的文章-黑侠的小圈子"}
            },
            {
                path: 'edit/:pinfo',
                component: () => import('../views/article/PerceptionEdit'),
                name: 'perceptionedit',
                meta: {title: "修改文章-黑侠的小圈子"}
            },
        ]
    },
    {path: '/errlog', component: () => import("../views/errLog"), meta: {title: "报错日志-黑侠的小圈子"}},
    {path: '/admin', component: () => import("../views/users/BackstageEcharts"), meta: {title: "用户数据可视化-黑侠的小圈子"}},
    {
        path: '*', component: () => import('../views/Home'), children: [
            {path: '', component: () => import('../views/Home_index'), meta: {title: "黑侠的小圈子"}},
        ]
    },

]

const router = new VueRouter({
    mode:'history',
    routes,
    //默认置顶，如果回退返回上次浏览的地方
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        }else if(to.meta.savedPosition){
            return to.meta.savedPosition
        }else {
            return {x: 0, y: 0}
        }
    }
})
router.beforeEach((to, from, next) => {
    /* 路由发生变化修改页面title */
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})
router.afterEach((to, from) => {
    if (to.meta.title) {
        wxChat.wxLogin(
            {
                title:to.meta.title
            }
        )
    }
})
export default router
